<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <el-form-item label="开户银行" prop="bankDesc">
                <el-input v-model="queryParams.bankDesc" placeholder="请输入开户银行"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="银行卡号" prop="bankNo">
                <el-input v-model="queryParams.bankNo" placeholder="请输入银行卡号"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="身份证号" prop="cardId">
                <el-input v-model="queryParams.cardId" placeholder="请输入身份证号"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="联系人" prop="contacter">
                <el-input v-model="queryParams.contacter" placeholder="请输入联系人"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="签约姓名" prop="contractName">
                <el-input v-model="queryParams.contractName" placeholder="请输入签约姓名"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="签约类型" prop="contractType">
                <el-input v-model="queryParams.contractType" placeholder="请输入签约类型"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="创建人" prop="createBy">
                <el-input v-model="queryParams.createBy" placeholder="请输入创建人"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="客户id" prop="customerId">
                <el-input v-model="queryParams.customerId" placeholder="请输入客户id"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
                <el-input v-model="queryParams.phone" placeholder="请输入联系电话"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="更新人" prop="updateBy">
                <el-input v-model="queryParams.updateBy" placeholder="请输入更新人"
                        clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="创建时间">
                <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange" range-separator="-" :default-time="['00:00:00', '23:59:59']" start-placeholder="开始日期" end-placeholder="结束日期"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
                           v-hasPermi="['bs:customerContract:saveOrUpdate']"
                >新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                        v-hasPermi="['bs:customerContract:delete']"
                >删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['bs:customerContract:export']"
                >导出</el-button>
            </el-col>
        </el-row>
        <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="开户银行" align="center" prop="bankDesc" :show-overflow-tooltip="true" />
            <el-table-column label="银行卡号" align="center" prop="bankNo" :show-overflow-tooltip="true" />
            <el-table-column label="身份证号" align="center" prop="cardId" :show-overflow-tooltip="true" />
            <el-table-column label="联系人" align="center" prop="contacter" :show-overflow-tooltip="true" />
            <el-table-column label="签约姓名" align="center" prop="contractName" :show-overflow-tooltip="true" />
            <el-table-column label="签约类型" align="center" prop="contractType" :show-overflow-tooltip="true" />
            <el-table-column label="创建人" align="center" prop="createBy" :show-overflow-tooltip="true" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="客户id" align="center" prop="customerId" :show-overflow-tooltip="true" />
            <el-table-column label="联系电话" align="center" prop="phone" :show-overflow-tooltip="true" />
            <el-table-column label="更新人" align="center" prop="updateBy" :show-overflow-tooltip="true" />
            <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.updateTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="handleShow(scope.row)"
                            v-hasPermi="['bs:customerContract:saveOrUpdate']">预览</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                            v-hasPermi="['bs:customerContract:saveOrUpdate']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                            v-hasPermi="['bs:customerContract:delete']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.nowPage" :limit.sync="queryParams.pageSize" @pagination="getPage"/>
        <!-- 查看签约信息详情对话框 -->
        <el-dialog :title="title" :visible.sync="showOpen" width="800px"  v-dialog-drag :close-on-click-modal='false'>
            <el-form ref="showForm" :model="showForm" :rules="rules" label-width="120px" >
                <el-form-item label="开户银行" prop="bankDesc">
                    <el-input v-model="showForm.bankDesc" style="width: 450px;"  type="text"  disabled placeholder="请输入开户银行" />
                </el-form-item>
                <el-form-item label="银行卡号" prop="bankNo">
                    <el-input v-model="showForm.bankNo" style="width: 450px;"  type="text"  disabled placeholder="请输入银行卡号" />
                </el-form-item>
                <el-form-item label="身份证号" prop="cardId">
                    <el-input v-model="showForm.cardId" style="width: 450px;"  type="text"  disabled placeholder="请输入身份证号" />
                </el-form-item>
                <el-form-item label="联系人" prop="contacter">
                    <el-input v-model="showForm.contacter" style="width: 450px;"  type="text"  disabled placeholder="请输入联系人" />
                </el-form-item>
                <el-form-item label="签约姓名" prop="contractName">
                    <el-input v-model="showForm.contractName" style="width: 450px;"  type="text"  disabled placeholder="请输入签约姓名" />
                </el-form-item>
                <el-form-item label="签约类型" prop="contractType">
                    <el-input v-model="showForm.contractType" style="width: 450px;"  type="text"  disabled placeholder="请输入签约类型" />
                </el-form-item>
                <el-form-item label="创建人" prop="createBy">
                    <el-input v-model="showForm.createBy" style="width: 450px;"  type="text"  disabled placeholder="请输入创建人" />
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                    <el-date-picker type="datetime" v-model="showForm.createTime" format="yyyy-MM-dd HH:mm:ss"
                                    value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" disabled placeholder="请选择创建时间" clearable>
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="客户id" prop="customerId">
                    <el-input v-model="showForm.customerId" style="width: 450px;"  type="text"  disabled placeholder="请输入客户id" />
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="showForm.phone" style="width: 450px;"  type="text"  disabled placeholder="请输入联系电话" />
                </el-form-item>
                <el-form-item label="更新人" prop="updateBy">
                    <el-input v-model="showForm.updateBy" style="width: 450px;"  type="text"  disabled placeholder="请输入更新人" />
                </el-form-item>
                <el-form-item label="更新时间" prop="updateTime">
                    <el-date-picker type="datetime" v-model="showForm.updateTime" format="yyyy-MM-dd HH:mm:ss"
                                    value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" disabled placeholder="请选择更新时间" clearable>
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelShow">关闭</el-button>
            </div>
        </el-dialog>
        <!-- 添加或修改签约信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px"  v-dialog-drag :close-on-click-modal='false'>
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-form-item label="开户银行" prop="bankDesc">
                    <el-input v-model="form.bankDesc" style="width: 450px;"  type="text" placeholder="请输入开户银行" />
                </el-form-item>
                <el-form-item label="银行卡号" prop="bankNo">
                    <el-input v-model="form.bankNo" style="width: 450px;"  type="text" placeholder="请输入银行卡号" />
                </el-form-item>
                <el-form-item label="身份证号" prop="cardId">
                    <el-input v-model="form.cardId" style="width: 450px;"  type="text" placeholder="请输入身份证号" />
                </el-form-item>
                <el-form-item label="联系人" prop="contacter">
                    <el-input v-model="form.contacter" style="width: 450px;"  type="text" placeholder="请输入联系人" />
                </el-form-item>
                <el-form-item label="签约姓名" prop="contractName">
                    <el-input v-model="form.contractName" style="width: 450px;"  type="text" placeholder="请输入签约姓名" />
                </el-form-item>
                <el-form-item label="签约类型" prop="contractType">
                    <el-input v-model="form.contractType" style="width: 450px;"  type="text" placeholder="请输入签约类型" />
                </el-form-item>
                <el-form-item label="创建人" prop="createBy">
                    <el-input v-model="form.createBy" style="width: 450px;"  type="text" placeholder="请输入创建人" />
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                    <el-date-picker type="datetime" v-model="form.createTime" format="yyyy-MM-dd HH:mm:ss"
                                    value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" placeholder="请选择创建时间" clearable>
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="客户id" prop="customerId">
                    <el-input v-model="form.customerId" style="width: 450px;"  type="text" placeholder="请输入客户id" />
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="form.phone" style="width: 450px;"  type="text" placeholder="请输入联系电话" />
                </el-form-item>
                <el-form-item label="更新人" prop="updateBy">
                    <el-input v-model="form.updateBy" style="width: 450px;"  type="text" placeholder="请输入更新人" />
                </el-form-item>
                <el-form-item label="更新时间" prop="updateTime">
                    <el-date-picker type="datetime" v-model="form.updateTime" format="yyyy-MM-dd HH:mm:ss"
                                    value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" placeholder="请选择更新时间" clearable>
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {getBsCustomerContractPage,getBsCustomerContractById,addOrUpdateBsCustomerContract,delBsCustomerContract,exportBsCustomerContract} from "@/api/project/bsCustomer/bsCustomerContract";
export default {
    name: "bsCustomerContract",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 总条数
            total: 0,
            // 参数表格数据
            configList: [],
            // 弹出层标题
            title: "",
            open: false,// 是否显示修改或增加的弹出层
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                nowPage: 1,
                pageSize: 10,
                bankDesc: undefined,
                bankNo: undefined,
                cardId: undefined,
                contacter: undefined,
                contractName: undefined,
                contractType: undefined,
                createBy: undefined,
                customerId: undefined,
                phone: undefined,
                updateBy: undefined,
            },
            // 表单参数
            form: {},
            showOpen: false,//是否显示查看工作内容弹出层
            showForm: {},
            // 表单校验
            rules: {
                bankDesc: [
                    {required: true, message: "开户银行不能为空", trigger: "blur"}
                ],
                bankNo: [
                    {required: true, message: "银行卡号不能为空", trigger: "blur"}
                ],
                cardId: [
                    {required: true, message: "身份证号不能为空", trigger: "blur"}
                ],
                contacter: [
                    {required: true, message: "联系人不能为空", trigger: "blur"}
                ],
                contractName: [
                    {required: true, message: "签约姓名不能为空", trigger: "blur"}
                ],
                contractType: [
                    {required: true, message: "签约类型不能为空", trigger: "blur"}
                ],
                createBy: [
                    {required: true, message: "创建人不能为空", trigger: "blur"}
                ],
                customerId: [
                    {required: true, message: "客户id不能为空", trigger: "blur"}
                ],
                phone: [
                    {required: true, message: "联系电话不能为空", trigger: "blur"}
                ],
                updateBy: [
                    {required: true, message: "更新人不能为空", trigger: "blur"}
                ],
            },
        };
    },
    created() {
        this.getPage();
    },
    methods: {
        /** 查询参数列表 */
        getPage(e) {
            this.loading = true;
            let params = '';
            if (e) {
                params = {nowPage: e.page, pageSize: e.limit}
            } else {
                params = {nowPage: this.queryParams.nowPage, pageSize: this.queryParams.pageSize}
            }
            getBsCustomerContractPage(params).then(response => {
                this.configList = response.data.records;
                this.total = response.data.total;
                this.loading = false;
            })
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                bankDesc: undefined,
                bankNo: undefined,
                cardId: undefined,
                contacter: undefined,
                contractName: undefined,
                contractType: undefined,
                createBy: undefined,
                createTime: undefined,
                customerId: undefined,
                phone: undefined,
                updateBy: undefined,
                updateTime: undefined,
            };
            this.showForm = {
                bankDesc: undefined,
                bankNo: undefined,
                cardId: undefined,
                contacter: undefined,
                contractName: undefined,
                contractType: undefined,
                createBy: undefined,
                createTime: undefined,
                customerId: undefined,
                phone: undefined,
                updateBy: undefined,
                updateTime: undefined,
            };
            this.resetForm("form");
            this.resetForm("showForm");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            let bankDesc = this.queryParams.bankDesc || '';
            let bankNo = this.queryParams.bankNo || '';
            let cardId = this.queryParams.cardId || '';
            let contacter = this.queryParams.contacter || '';
            let contractName = this.queryParams.contractName || '';
            let contractType = this.queryParams.contractType || '';
            let createBy = this.queryParams.createBy || '';
            let customerId = this.queryParams.customerId || '';
            let phone = this.queryParams.phone || '';
            let updateBy = this.queryParams.updateBy || '';
            let time = this.dateRange || '';
            let params = {
                bankDesc: bankDesc,
                bankNo: bankNo,
                cardId: cardId,
                contacter: contacter,
                contractName: contractName,
                contractType: contractType,
                createBy: createBy,
                customerId: customerId,
                phone: phone,
                updateBy: updateBy,
                startTime: time[0],
                endTime: time[1],
                nowPage: 1,
                pageSize: this.queryParams.pageSize
            };
            getBsCustomerContractPage(params).then(res => {
                if (res.code == 200) {
                    this.configList = res.data.records;
                    this.total = res.data.total;
                    this.loading = false;
                }
            })
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.queryParams.bankDesc = '';
            this.queryParams.bankNo = '';
            this.queryParams.cardId = '';
            this.queryParams.contacter = '';
            this.queryParams.contractName = '';
            this.queryParams.contractType = '';
            this.queryParams.createBy = '';
            this.queryParams.customerId = '';
            this.queryParams.phone = '';
            this.queryParams.updateBy = '';
            this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加签约信息信息";
        },
        //多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id);
            this.single = selection.length != 1;
            this.multiple = !selection.length
        },
        /** 查看按钮操作 */
        handleShow(row) {
            this.reset();
            const id = row.id || '';
            getBsCustomerContractById({id}).then(response => {
                this.showForm = response.data;
                this.showOpen = true;
                this.title = "签约信息详情";
            });
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || '';
            getBsCustomerContractById({id}).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改签约信息信息";
            });
        },
        cancelShow: function () {
            this.showOpen = false;
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id !== undefined) {
                        addOrUpdateBsCustomerContract(this.form).then(res => {
                            if (res.code == 200) {
                                this.msgSuccess("修改成功");
                                this.open = false;
                                this.getPage();
                            } else {
                                this.msgError(res.msg);
                            }
                        })
                    } else {
                        addOrUpdateBsCustomerContract(this.form).then(res => {
                            if (res.code == 200) {
                                this.msgSuccess("新增成功");
                                this.open = false;
                                this.getPage();
                            } else {
                                this.msgError(res.msg);
                            }
                        })
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$confirm('是否确认删除签约信息编号为"' + ids + '"的数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delBsCustomerContract(ids);
            }).then(() => {
                this.getPage();
                this.msgSuccess("删除成功");
            }).catch(function () {
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有签约信息数据项?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return exportBsCustomerContract(queryParams);
            }).then(res => {
                this.download(res.data);
            }).catch(function () {
            });
        },
    }
};
</script>
<style>

</style>
